*Gender Differences in Informal Labor Market Resilience
*Code to produce all tables and figures
*Authors: Morgan Hardy, Erin Litzow, Jamie McCasland, and Gisella Kagy
*contact litzow.erin@gmail.com with any questions about data and/or code

**********************
**SETTING FILE PATHS**
**********************

clear all

global main = "/Users/erinlitzow/Dropbox/SEEFA Surveys/2020/3 - Data/Data Analysis/WBER Publication/" // main folder - where you set this main folder, make three subfolders "code", "data", "output"
//put this do file in "code", put all the .dta files in "data", all output will show up in the "output" folder

global code = "${main}code/" // folder with Stata code
global data = "${main}data/" // folder with data
global output = "${main}output/" // folder with output

***************************************************
***************************************************
use "${data}owner_panel", clear

**FIGURE 2, APPENDIX FIGURE A1, APPENDIX FIGURE A2
estimates clear
foreach var in sales profits hours {
	estimates clear
	foreach i of numlist 1/6 {
		preserve
		keep if month==`i'
		rename male male_`i'
		eststo month_`i'_m: xi: reg `var'gr0_ i.male if sample=="H" & insample_`var'==1 & male==1, nocons
		gen female = ( male_`i'==0 )
		drop male
		rename female male_`i'
		eststo month_`i'_f: xi: reg `var'gr0_ i.male if sample=="H" & insample_`var'==1 & male==1, nocons
		restore
	}
coefplot (month_1_m \ month_2_m \ month_3_m \ month_4_m \ month_5_m \ month_6_m, label(Male) mcolor(blue) msymbol(triangle) msize(mediumlarge) ciopts(lcolor(blue))) (month_1_f \ month_2_f \ month_3_f \ month_4_f \ month_5_f \ month_6_f, label(Female) mcolor(red) ciopts(lcolor(red))),  coeflabels(_Imale_1_1 = "Feb" _Imale_2_1 = "Mar" _Imale_3_1 = "Apr" _Imale_4_1 = "May" _Imale_5_1 = "Jun" _Imale_6_1 = "Jul") vertical graphregion(color(white)) ytitle("Share of firms") name(levels_`var'gr0_, replace)
}

graph display levels_salesgr0_
graph save "${output}Figure2", replace
graph display levels_profitsgr0_
graph save  "${output}FigureA1", replace
graph display levels_hoursgr0_
graph save  "${output}FigureA2", replace

*testing for significance of differences
foreach var in sales profits hours {
	foreach month in 1 2 3 4 5 6 {
		display "`var' month = `month'"
		ttest `var'gr0_ if month==`month' & insample_`var'==1, by(male)
	}
}

***************************************************
***************************************************
use "${data}owners", clear

*dropping firms with zero sales in Feb
keep if insample_sales==1
*winsorizing the top earning female-owned firm for visual clarity
replace sales_1 = 1500 if sales_1==6500

**FIGURE 3, PANEL A
*Females
ksmirnov sales_1 if male==0, by(close3mo_s) exact
local pvalf: display %6.3f `r(p_exact)'

twoway kdensity sales_1 if male==0 & close3mo_s==1, fcolor(blue%30) lcolor(blue) lpattern(dash) || kdensity sales_1 if male==0 & close3mo_s==0, fcolor(green%30) lcolor(green) xlabel(0(200)1800) xtitle("Female owners' Feb. 2020 sales, GH¢") ytitle("kdensity of Feb. 2020 sales") legend(label(1 "Persistent closers") label(2 "Non-persistent closers")) graphregion(color(white)) text(0.0035 600 "Two-sample Kolmogorov-Smirnov test for" "equality of distribution functions:" "exact p-val = `pvalf'", place(se) box just(center) margin(l+1 t+1 b+1) fcolor(white))
graph export "${output}Figure3_PanelA.jpg", replace

**FIGURE 3, PANEL B
*Males
ksmirnov sales_1 if male==1, by(close3mo_s) exact
local pvalm: display %6.3f `r(p_exact)'

twoway kdensity sales_1 if male==1 & close3mo_s==1, fcolor(blue%30) lcolor(blue) lpattern(dash) || kdensity sales_1 if male==1 & close3mo_s==0, fcolor(green%30) lcolor(green) xlabel(0(200)1800) xtitle("Male owners' Feb. 2020 sales, GH¢") ytitle("kdensity of Feb. 2020 sales") legend(label(1 "Persistent closers") label(2 "Non-persistent closers")) graphregion(color(white)) text(0.002 700 "Two-sample Kolmogorov-Smirnov test for" "equality of distribution functions:" "exact p-val = `pvalm'", place(se) box just(center) margin(l+1 t+1 b+1) fcolor(white))
graph export "${output}Figure3_PanelB.jpg", replace

**FIGURE 1
ksmirnov sales_1, by(male) exact
local pvalm: display %6.3f `r(p_exact)'

twoway kdensity sales_1 if male==1, fcolor(blue%30) lcolor(blue) lpattern(dash) || kdensity sales_1 if male==0, fcolor(green%30) lcolor(red) xlabel(0(200)1800) xtitle("Owners' Feb. 2020 sales, GH¢") ytitle("kdensity of Feb. 2020 sales") legend(label(1 "Males") label(2 "Females")) graphregion(color(white)) text(0.002 700 "Two-sample Kolmogorov-Smirnov test for" "equality of distribution functions:" "exact p-val = `pvalm'", place(se) box just(center) margin(l+1 t+1 b+1) fcolor(white))
graph export "${output}Figure1.jpg", replace

**APPENDIX FIGURE A3
gen anyothrinc = 0
replace anyothrinc = 1 if selfemp_count_1 > 0 | anyfarm_1 > 0 | wagejob_count_1 > 0

foreach i of numlist 0/1 {
	dis "male = `i'"
	ttest sales_1 if male == `i', by(anyothrinc)
}

*Panel B: Males 
ksmirnov sales_1 if male==1, by(anyothrinc) exact
local pvalm: display %6.3f `r(p_exact)'

twoway kdensity sales_1 if anyothrinc==1 & male==1, fcolor(blue%30) lcolor(blue) lpattern(dash) || kdensity sales_1 if anyothrinc==0 & male==1, fcolor(green%30) lcolor(red) xlabel(0(200)1800) xtitle("Male Owners' Feb. 2020 sales, GH¢") ytitle("kdensity of Feb. 2020 sales") legend(label(1 "Have outside option in Feb") label(2 "No outside option in Feb")) graphregion(color(white)) text(0.002 700 "Two-sample Kolmogorov-Smirnov test for" "equality of distribution functions:" "exact p-val = `pvalm'", place(se) box just(center) margin(l+1 t+1 b+1) fcolor(white))
graph export "${output}FigureA3_PanelB.jpg", replace

*Panel A: Females 
ksmirnov sales_1 if male==0, by(anyothrinc) exact
local pvalm: display %6.3f `r(p_exact)'

twoway kdensity sales_1 if anyothrinc==1 & male==0, fcolor(blue%30) lcolor(blue) lpattern(dash) || kdensity sales_1 if anyothrinc==0 & male==0, fcolor(green%30) lcolor(red) xlabel(0(200)1800) xtitle("Female Owners' Feb. 2020 sales, GH¢") ytitle("kdensity of Feb. 2020 sales") legend(label(1 "Have outside option in Feb") label(2 "No outside option in Feb")) graphregion(color(white)) text(0.002 700 "Two-sample Kolmogorov-Smirnov test for" "equality of distribution functions:" "exact p-val = `pvalm'", place(se) box just(center) margin(l+1 t+1 b+1) fcolor(white))
graph export "${output}FigureA3_PanelA.jpg", replace

***************************************************
***************************************************
use "${data}owner_panel", clear

rename close3mo_s close3mo_s1

merge m:1 caseid_rand using "${data}owners", keepusing(close3mo_s)

**TABLE 1
estimates clear
gen after = 0 if month == 1
replace after = 1 if inlist(month, 2, 3, 4, 5, 6)
gen maleafter = male * after

keep if inlist(month, 1, 2, 3, 4, 5, 6)

*sales GHC 
eststo: reg sales_ after if insample_sales == 1 & male == 0, cluster(caseid_rand)
eststo: reg sales_ after if insample_sales == 1 & male == 1, cluster(caseid_rand)
eststo: reg sales_ male after maleafter if insample_sales == 1, cluster(caseid_rand)

*sales>0
eststo: reg salesgr0_ after if insample_sales == 1 & male == 0, cluster(caseid_rand)
eststo: reg salesgr0_ after if insample_sales == 1 & male == 1, cluster(caseid_rand)
eststo: reg salesgr0_ male after maleafter if insample_sales == 1, cluster(caseid_rand)

*Sales GHC if sales >0 
eststo: reg sales_ after if insample_sales == 1 & sales_ > 0 & male == 0, cluster(caseid_rand)
eststo: reg sales_ after if insample_sales == 1 & sales_ > 0 & male == 1, cluster(caseid_rand)
eststo: reg sales_ male after maleafter if insample_sales == 1 & sales_ > 0, cluster(caseid_rand)

*Sales GHC if non persistent closers
eststo: reg sales_ after if insample_sales == 1 & close3mo_s == 0 & male == 0, cluster(caseid_rand)
eststo: reg sales_ after if insample_sales == 1 & close3mo_s == 0 & male == 1, cluster(caseid_rand)
eststo: reg sales_ male after maleafter if insample_sales == 1 & close3mo_s == 0, cluster(caseid_rand)

*closure
eststo: reg close3mo_s male if insample_sales == 1 & month == 1, cluster(caseid_rand)
 
esttab using "${output}Table1", label replace r2 scalars(N_clust) tex se starlevels(* 0.1 ** 0.05 *** 0.01)

**APPENDIX TABLE A4
estimates clear
foreach var of varlist profits_ profitsgr0_ {
	eststo: reg `var' after if male==0 & insample_profits==1, cluster(caseid_rand)
	eststo: reg `var' after if male==1 & insample_profits==1, cluster(caseid_rand)
	eststo: reg `var' male after maleafter if insample_profits==1, cluster(caseid_rand)
}	

foreach var of varlist  hours_ hoursgr0_ {
	eststo: reg `var' after if male==0 & insample_hours==1, cluster(caseid_rand)
	eststo: reg `var' after if male==1 & insample_hours==1, cluster(caseid_rand)
	eststo: reg `var' male after maleafter if insample_hours==1, cluster(caseid_rand)
}	
esttab using "${output}TableA4", label append r2 scalars(N_clust) tex se starlevels(* 0.1 ** 0.05 *** 0.01)

***************************************************
***************************************************
use "${data}owners", clear

keep if insample_sales==1

gen selfemp_reason_money = 1 if selfemployed_reason == "Earn a living" | selfemployed_reason == "For money" | selfemployed_reason == "For profit" |selfemployed_reason == "I make lot of money" | selfemployed_reason == "Make money" | selfemployed_reason == "Makes a lot of money" | selfemployed_reason == "To make money" | selfemployed_reason == "Support family" | selfemployed_reason == "Support husband"
replace selfemp_reason_money = 0 if selfemp_reason_money == .

gen selfemp_reason_interest = 1 if selfemployed_reason == "Have interest" | selfemployed_reason == "Interested in sewing" | selfemployed_reason == "Interested in sewing " | selfemployed_reason == "Love making dresses" | selfemployed_reason == "Want to teach more people in garment"
replace selfemp_reason_interest = 0 if selfemp_reason_interest == .

gen selfemp_reason_boss = 1 if selfemployed_reason == "Own boss" | selfemployed_reason == "Own business"
replace selfemp_reason_boss = 0 if selfemp_reason_boss == .

gen othjob_1 = 0 if wagejob_count_1 == 0 & selfemp_count_1 == 0
replace othjob_1 = 1 if wagejob_count_1 == 1 | selfemp_count_1 == 1

gen childgr0_1 = (hh_child_1>0)
gen reason_children_01 = 1 if reason_children==4
replace reason_children_01 = 0 if reason_children==1 | reason_children==2 | reason_children==3
gen reason_boss_01 = 1 if reason_boss==3 | reason_boss==4
replace reason_boss_01 = 0 if reason_boss==1 | reason_boss==2
gen reason_no_wage_01 = 1 if reason_no_wage==3 | reason_no_wage==4
replace reason_no_wage_01 = 0 if reason_no_wage==1 | reason_no_wage==2
gen reason_growth_01 = 1 if reason_growth==4
replace reason_growth_01 = 0 if reason_growth==1 | reason_growth==2 | reason_growth==3

gen anyothrinc = 0
replace anyothrinc = 1 if selfemp_count_1 > 0 | anyfarm_1 > 0 | wagejob_count_1 > 0

format sales_1 wages_1 anywork lab_tot_paid_feb tenure age schooling married_1 hhhead_1 childgr0_1 selfemp_reason_* anyothrinc risk2 anyfarm_1 othjob_1 %03.2f

**TABLE 2
balancetable (mean if male==0 & close3mo_s==0) (mean if male==0 & close3mo_s==1) (diff close3mo_s if male==0) (mean if male==1 & close3mo_s==0) (mean if male==1 & close3mo_s==1) (diff close3mo_s if male==1) sales_1 wages_1 lab_tot_paid_feb tenure age schooling married_1 childgr0_1 anyothrinc using "${output}Table2.xls", displayformat ctitles("Female owners, <=3 months with zero sales" "Female owners, >3 months with zero sales" "Female difference" "Male owners, <=3 months with zero sales" "Male owners, >3 months with zero sales" "Male difference") varlabels wrap(indent) replace vce(robust)

***************************************************
***************************************************
use "${data}owner_panel", clear

*dropping firms with zero sales in Feb
keep if insample_sales==1 

preserve
keep if month==1
keep caseid_rand totinc_ tothours_gr0 profits_ tototherinc_ 
foreach var of varlist totinc_ tothours_gr0 profits_ tototherinc_  {
	rename `var' `var'feb
}
tempfile febmeasures
save "`febmeasures'", replace
restore

merge m:1 caseid_rand using "`febmeasures'"

**TABLE 3
estimates clear
foreach var of varlist totinc_ tothours_gr0 profits_ tototherinc_ {
	eststo: reg `var' i.close3mo_s `var'feb if month==6 & male==0, r
	eststo: reg `var' i.close3mo_s `var'feb if month==6 & male==1, r
	eststo: reg `var' i.male##i.close3mo_s `var'feb if month==6, r
}
esttab using "${output}Table3", label replace r2 scalars(N_clust) csv se starlevels(* 0.1 ** 0.05 *** 0.01) drop(1.male *feb)

***************************************************
***************************************************
use "${data}owners", clear

keep if insample_sales==1

gen covid_demand=1 if covid_q1_1==1 | covid_q1_2==1
replace covid_demand=0 if (covid_q1_1==. | covid_q1_1==0) & (covid_q1_2==. | covid_q1_2==0)
replace covid_demand=. if covid_q1_1==.& covid_q1_2==.

gen covid_supply=1 if covid_q1_3==1 | covid_q1_4==1
replace covid_supply=0 if (covid_q1_3==. | covid_q1_3==0) & (covid_q1_4==. | covid_q1_4==0)
replace covid_supply=. if covid_q1_3==.& covid_q1_4==.

gen covid_labor=1 if covid_q1_5==1 | covid_q1_6==1
replace covid_labor=0 if (covid_q1_5==. | covid_q1_5==0) & (covid_q1_6==. | covid_q1_6==0)
replace covid_labor=. if covid_q1_5==.& covid_q1_6==.

gen covid_money=1 if covid_q2_5==1 | covid_q2_7==1
replace covid_money=0 if (covid_q2_5==. | covid_q2_5==0) & (covid_q2_7==. | covid_q2_7==0)
replace covid_money=. if covid_q2_5==.& covid_q2_7==.

format covid_demand covid_supply covid_labor covid_program covid_q2_1 covid_q2_3 covid_q2_4 covid_money %03.2f

**APPENDIX TABLE A1
balancetable (mean if male==0) (mean if male==1) (diff male) covid_demand covid_supply covid_labor covid_program covid_q2_1 covid_q2_3 covid_q2_4 covid_money using "${output}TableA1.tex", displayformat ctitles("Female owners" "Male owners" "Difference") varlabels wrap(indent) replace vce(robust)

***************************************************
***************************************************
use "${data}owners", clear
keep if insample_sales == 1 //sample of 490 firms used for main analyses in this paper
keep caseid_rand
gen analysissample = 1
merge 1:1 caseid_rand using "${data}hohoe_census_full.dta" //data from 2019 census of firms
drop if _merge==2
drop _merge
tempfile analysissample
save "`analysissample'", replace

use "${data}samplingframe.dta", clear //firms identified in census that were still operating as of Jan. 2020
append using "${data}interviewed.dta" //all firms whom we successfully contacted via the phone survey, if interview not completed firm was found to not be eligible (e.g. no longer operating)
append using "`analysissample'" //final set of 490 firms used in analysis, i.e. those who completed the phone survey and had >0 sales in Feb 2020

gen s_v_i = 0 if interviewed == 1
replace s_v_i = 1 if samplingframe == 1
gen i_v_a = 0 if analysissample == 1
replace i_v_a = 1 if interviewed == 1
gen s_v_a = 0 if analysissample == 1
replace s_v_a = 1 if samplingframe == 1

gen male=1 if gender=="M"
replace male=0 if gender=="F"
gen reason_money = 1 if selfemployed_reason == "Earn a living" | selfemployed_reason == "For money" | selfemployed_reason == "For profit" | selfemployed_reason == "I make lot of money" | selfemployed_reason == "Make money" | selfemployed_reason == "Makes a lot of money" | selfemployed_reason == "To make money" | selfemployed_reason == "Support family" | selfemployed_reason == "Support husband"
replace reason_money = 0 if reason_money==. & selfemployed_reason != ""
gen reason_interest = 1 if selfemployed_reason == "Want to teach more people in garment" | selfemployed_reason == "Love making dresses" | selfemployed_reason == "Interested in sewing " | selfemployed_reason == "Interested in sewing" | selfemployed_reason == "Have interest"
replace reason_interest = 0 if reason_interest==. & selfemployed_reason != ""
gen reason_ownboss = 1 if selfemployed_reason == "Own business" | selfemployed_reason == "Own boss"
replace reason_ownboss = 0 if reason_ownboss==. & selfemployed_reason != ""

label var business_tenure "No. of years in the garment business"
label var business_tenure_hohoe "No. of years in the garment business in Hohoe"
label var apprentice "No. of apprentices"
label var paidworker "No. of paid workers"
label var unpaidworker "No. of unpaid workers"
label var reason_money "Reason for self-employment: make money"
label var reason_interest "Reason for self-employment: interest in garment making"
label var reason_ownboss "Reason for self-employment: be own boss"
label var hohoe_contact "No. of garment makers known in Hohoe"
label var outside_hohoe_contact "No. of garment makers known outside Hohoe"

format male hohoe_contact outside_hohoe_contact apprentice paidworker unpaidworker reason_money reason_interest reason_ownboss business_tenure business_tenure_hohoe %03.2f

**APPENDIX TABLE A2
*female-owned firms
balancetable (mean if samplingframe == 1 & male == 0) (mean if interviewed == 1 & male == 0) (mean if analysissample == 1 & male == 0) (diff s_v_i if male==0) (diff i_v_a if male==0) (diff s_v_a if male==0) business_tenure business_tenure_hohoe apprentice paidworker unpaidworker reason_money reason_interest reason_ownboss hohoe_contact outside_hohoe_contact using "${output}TableA2.tex", displayformat ctitles("Open in Jan 2020" "Interviewed" ">0 sales in Feb 2020" "Diff. (open - interviewed)" "Diff. (interviewed - analysis)" "Diff. (open - analysis)") varlabels wrap(indent) replace vce(robust)

**APPENDIX TABLE A3
*male-owned firms
balancetable (mean if samplingframe == 1 & male == 1) (mean if interviewed == 1 & male == 1) (mean if analysissample == 1 & male == 1) (diff s_v_i if male==1) (diff i_v_a if male==1) (diff s_v_a if male==1) business_tenure business_tenure_hohoe apprentice paidworker unpaidworker reason_money reason_interest reason_ownboss hohoe_contact outside_hohoe_contact using "${output}TableA3.tex", displayformat ctitles("Open in Jan 2020" "Interviewed" ">0 sales in Feb 2020" "Diff. (open - interviewed)" "Diff. (interviewed - analysis)" "Diff. (open - analysis)") varlabels wrap(indent) replace vce(robust)
